import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:znmm/UI/A_Common/image/cached_network_Image.dart';
import 'package:znmm/UI/ProductPages/view/product_category_view.dart';
// import 'package:get/get.dart';
// import 'package:glassesin/config/app_routes.dart';

class BestSellersView extends StatefulWidget {
  const BestSellersView({super.key});

  @override
  State<BestSellersView> createState() => _BestSellersViewState();
}

class _BestSellersViewState extends State<BestSellersView> {
  final List<String> _imageList = [];

  @override
  void initState() {
    super.initState();

    // _imageList.add("https://www.glassesin.com/image/home/1.webp");
    // _imageList.add("https://www.glassesin.com/image/home/2.webp");
    // _imageList.add("https://www.glassesin.com/image/home/3.webp");
    // _imageList.add("https://www.glassesin.com/image/home/4.jpg");
    // _imageList.add("https://www.glassesin.com/image/home/5.jpg");

    _imageList.add("https://www.glassesin.com/image/home/top1.jpg");
    _imageList.add("https://www.glassesin.com/image/home/top2.webp");
    _imageList.add("https://www.glassesin.com/image/home/top3.jpg");
    _imageList.add("https://www.glassesin.com/image/home/top4.jpg");
    _imageList.add("https://www.glassesin.com/image/home/top5.webp");
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 200,
      margin: const EdgeInsets.fromLTRB(10, 0, 10, 0),
      child: ListView.separated(
        scrollDirection: Axis.horizontal,
        itemCount: _imageList.length,
        itemBuilder: (_, index) {
          return GestureDetector(
            onTap: () {
              Get.to(const ProductCategoryView());
            },
            child: Stack(
              children: [
                Container(
                  width: 160, // 设置一个固定宽度，例如200
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(6.0),
                    border: Border.all(
                      color: Colors.grey.shade100, // 边框颜色
                      width: 0.5, // 边框宽度
                    ),
                  ),
                  child: ClipRRect(
                    borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(6.0),
                      topRight: Radius.circular(6.0),
                      bottomLeft: Radius.circular(6.0),
                      bottomRight: Radius.circular(6.0),
                    ),
                    // child: Image.asset(
                    //   _imageList[index],
                    //   fit: BoxFit.cover,
                    // ),
                    child: CachedNetworkImageLoader(
                      imageUrl: _imageList[index],
                    ),
                  ),
                ),
                // Positioned(
                //   top: 12.0,
                //   left: 18.0,
                //   child: Text(
                //     "TOP:${index + 1}",
                //     style: const TextStyle(
                //       color: Colors.red,
                //       fontSize: 16.0,
                //       fontWeight: FontWeight.bold,
                //       shadows: [
                //         Shadow(
                //           color: Colors.black,
                //           offset: Offset(2, 2),
                //           blurRadius: 3,
                //         ),
                //       ],
                //     ),
                //   ),
                // ),
              ],
            ),
          );
        },
        separatorBuilder: (BuildContext context, int index) {
          return const Padding(padding: EdgeInsets.only(left: 10));
        },
      ),
    );
  }
}
